library(tidyverse)
## ── Attaching packages ──────────────────────────────────────────────────────────────────────────────── tidyverse 1.2.1 ──
## ✔ ggplot2 3.2.1 ✔ purrr 0.3.3
## ✔ tibble 2.1.3 ✔ dplyr 0.8.3
## ✔ tidyr 1.0.0 ✔ stringr 1.4.0
## ✔ readr 1.3.1 ✔ forcats 0.4.0
## ── Conflicts ─────────────────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
library(viridis)
## Loading required package: viridisLite
library(p8105.datasets)
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
data("instacart")
insta_data = instacart %>%
filter(department == "beverages") %>%
mutate(reordered = recode(reordered, "1" = "Yes", "0" = "No"),
order_dow = recode(order_dow, "0" = "Sunday", "1" = "Monday", "2" = "Tuesday",
"3" = "Wednesday", "4" = "Thursday", "5" = "Friday", "6" = "Saturday")) %>%
select (aisle, product_name, order_hour_of_day, order_dow, reordered)
count = insta_data %>%
group_by(aisle) %>%
summarize(reordered = n())
count
## # A tibble: 8 x 2
## aisle reordered
## <chr> <int>
## 1 cocoa drink mixes 1062
## 2 coffee 8392
## 3 energy sports drinks 4742
## 4 juice nectars 14350
## 5 refrigerated 23228
## 6 soft drinks 16279
## 7 tea 9376
## 8 water seltzer sparkling water 36617
Bar Chart
- Number of times goods from each aisle were reorderd within the beverage department.
count %>%
plot_ly(x = ~aisle, y = ~reordered, color = ~aisle, type = "bar", text = ~aisle) %>%
layout(xaxis = list(title = "Aisle Category"),
yaxis = list(title = "Total items reordered"))
Boxplot
- Distribution of each aisle being purchased across all hours of day.
insta_data %>%
plot_ly(x = ~aisle, y = ~order_hour_of_day, color = ~aisle, type = "box") %>%
layout(xaxis = list(title = "Aisle Category"),
yaxis = list(title = "Hour of Day Ordered"))
Line plot
- Number of times goods from each aisle were reorderd within the beverage department.